package net.haiyue.api.service;

import net.haiyue.api.entity.Project;
import net.haiyue.api.entity.SelectInfo;
import net.haiyue.api.entity.User;
import net.haiyue.api.repository.ProjectRepository;
import net.haiyue.api.repository.UserRepository;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

@Service
public class ProjectService {
    @Resource
    private ProjectRepository _repository;
    @Resource
    private UserRepository _userRepository;

    public List<Project> all() {
        return _repository.findAll();
    }

    public List<SelectInfo> selectProject(String email){
//        if (email!=null){
//            //判断email是否为admin权限
//            User userByEmail = _userRepository.findUserByEmail(email);
//            if (userByEmail.isIs_admin()){
//                return _repository.selectProject();
//            }else {
//                return  _repository.selectFilterProject(userByEmail.getId());
//            }
//        }
        return _repository.selectProject();
    }

    public Project add(Project project){
        return _repository.saveAndFlush(project);
    }
}
